# -*- coding: UTF-8 -*-
import numpy as np

from business.logger import Logger
from business.zardehoperator import ZardehOperator

# 初始化日志
log = Logger("dealmatrix").logger


# print('输入模糊矩阵行列数:')
# temp = input()
# fuzzyElement = int(temp)
# print('你输入的行列数为：' + temp)
def delMatrix(fuzzyElement, arg_element=[]):
    fuzzyMatrix = np.arange(fuzzyElement * fuzzyElement)
    fuzzyMatrix = fuzzyMatrix.reshape((fuzzyElement, fuzzyElement))
    fuzzyMatrix = fuzzyMatrix.astype(np.float)
    element_index = 0
    for y in range(0, fuzzyElement):
        for x in range(0, fuzzyElement):
            # m = float(input()) #手动输入元素,用于调试
            fuzzyMatrix[y][x] = arg_element[element_index]
            element_index = element_index + 1
    fr_closure = ZardehOperator.transitiveMatrix(fuzzyElement, fuzzyMatrix)
    TR = 2
    while not (fr_closure == fuzzyMatrix).all():
        fuzzyMatrix = fr_closure
        fr_closure = ZardehOperator.transitiveMatrix(fuzzyElement, fuzzyMatrix)
        TR = (TR * 2)
    log.info("闭包次数为：")
    if TR == 2:
        log.info(TR)
    else:
        TR = TR / 2
        log.info(TR)
    trans_dict = {'closure_times': TR, 'closure_Matrix': fr_closure}
    return trans_dict
